﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChartSharp
{
    public class Title : ChartParam
    {
        protected string _title;
        protected string _color;
        protected int? _size;

        public override string Name
        {
            get { return "chtt"; }
        }

        public override string Data
        {
            get
            {
                StringBuilder builder = new StringBuilder();

                builder.Append(_title);
                builder.Replace("\r\n", "\n");
                builder.Replace("\n", "|");
                builder.Replace(" ", "+");

                if (_color != null)
                {
                    builder.Append("&chts=");
                    builder.Append(_color);

                    if (_size.HasValue)
                    {
                        builder.Append(",");
                        builder.Append(_size);
                    }
                }

                return builder.ToString();
            }
        }

        public Title(string title)
        {
            _title = title.Replace(Environment.NewLine, "|").Replace(" ", "+");
        }

        public Title(string title, string color)
            : this(title)
        {
            _color = color;
        }

        public Title(string title, string color, int size)
            : this(title, color)
        {
            _size = size;
        }
    }
}
